﻿
@{
    ViewBag.Title = "EstUserContrastView";
    Layout = "~/Views/Shared/_MyLayout.cshtml";
}

@*用户工程测算 联合对比*@
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>前期测算对比</legend>
</fieldset>
<div>
    <form class="layui-form" enctype="multipart/form-data">
        <div class="layui-form-item">
            <label class="layui-form-label">主项目选择</label>
            <div class="layui-input-inline" style="width:500px;">
                <select name="ProjectId" lay-verify="required" lay-search lay-filter="ProjectSelFilter" id="ProjectSel">
                    <option value=""></option>
                    @for (int i = 0; i < ViewBag.ProjectList.Count; i++)
                    {
                        <option value="@ViewBag.ProjectList[i]["ProjectId"]">@ViewBag.ProjectList[i]["Name"]|@ViewBag.ProjectList[i]["ProjectCode"]|@ViewBag.ProjectList[i]["Type"]</option>
                    }
                </select>
            </div>
            <button type="button" class="layui-btn" style="float:left;" id="BtnContrast"><i class="layui-icon">&#xe61f;</i>对比</button>
            <button type="button" class="layui-btn layui-btn-danger" style="float:left;" id="BtnClear"><i class="layui-icon">&#xe61f;</i>清除</button>
        </div>
    </form>
</div>
<div class="layui-card">
    <div class="layui-card-header">
        <div>待比较的测算表</div>
    </div>
    <div class="layui-card-body" id="ToContrList">
        @*卡片式面板面板通常用于非白色背景色的主体内<br>
        从而映衬出边框投影*@


    </div>
</div>

    <table id="CSTable" lay-filter="CSTableFilter"></table>




<script type="text/javascript">
    var table;
    var EstIds = [];
    var EstCount = 0;
    layui.use(['form', 'table', 'upload', 'layer', 'element'], function () {
        var element = layui.element;
        var form = layui.form;
        table = layui.table;
        var tab = parent.tab;
        var layer = layui.layer;
        var index;
        var layerCopyIndex;
        var ProjectType = "";
        var ProjectName = "";
        var ProjectId = "";
        var ProjectCode = "";

        $("#BtnClear").on("click", function () {
            $("#ToContrList").empty();
            EstIds = [];
            EstCount = 0;
        });

        $("#BtnContrast").on("click", function () {
            if (EstIds.length == 0) {
                alert("请选择前期测算表");
                return;
            }
            var tempNum = 5 - EstIds.length;
            for (var i = 0; i < tempNum; i++) {
                EstIds.push(-1);
            }

            window.open("/Estimate/PEUserConCSView?t1=" + EstIds[0] + "&t2=" + EstIds[1] + "&t3=" + EstIds[2] + "&t4=" + EstIds[3] + "&t5=" + EstIds[4]);


        })


        form.on('select(ProjectSelFilter)', function (data) {
            //console.log(data.elem); //得到select原始DOM对象
            //console.log(data.value); //得到被选中的值
            //console.log(data.othis); //得到美化后的DOM对象

            ProjectId = data.value;
            if (data.value == "") {
                return;
            }
            //下面需要先查工程类型           
            $.ajax({
                type: "POST",
                url: "/Project/QueryProjectInfo",
                async: false,
                data: { "ProjectId": data.value },
                success: function (msg) {
                    if (msg.result == "OK") {
                        table.reload("CSTable", {
                            where: {
                                SortName: "PreEstId", Order: "Desc", Condition: " and IsDelete<>1 and Type='用户工程前期测算' and ProjectId=" + data.value
                            }
                        });
                        ProjectType = msg.type;
                        ProjectName = msg.Name;
                    } else {
                        alert(msg.result);
                        return;
                    }
                }
            });
        });


        table.render({
            elem: '#CSTable'
            , method: 'post'
            //, height: 315
            , url: '/Estimate/EstUserCSTableRequest' //数据接口
            , page: true //开启分页
            , where: { SortName: "PreEstId", Order: "Desc", Condition: " and 1=0" }
            , limits: [10, 50, 100]
            , cols: [[ //表头
                { field: 'Name', title: '前期测算表名称', width: 250, edit: 'text', }
                , {
                    field: "operation", title: "操作", width: 200, fixed: 'right',
                    templet: function (d) {
                        return '<a class="layui-btn layui-btn-xs" lay-event="detail">加入对比</a>';
                    }
                }
            ]]
        });


        table.on("tool(CSTableFilter)", function (obj) {
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的DOM对象

            var EstName;
            var PreEstId;
            var tempProjectName;

            if (layEvent == 'detail') {
                //parent.layui.index.openTabsPage('/SubContract/SubConInfoEditView?SubContractId=' + data.SubContractId, '分包合同编辑');
                var type = $("#ProjectSel").find("option:selected").text();
                //alert(data);
                if (EstCount >= 5) {
                    alert("对比数目超过上限");
                    return;
                }
                EstName = data.Name;
                PreEstId = data.PreEstId;
                tempProjectName = ProjectName;
                $("#ToContrList").append(tempProjectName + "|" + EstName + "<br\>");

                //这里操作把数组里面的[-1]去掉。
                var tempNum = EstIds.length;
                for (var i = 0; i < tempNum; i++) {
                    if (EstIds[i] == -1) {
                        EstIds.splice(i, 1);
                        i--;
                        tempNum--;
                    }                 
                }
                EstIds.push(PreEstId);

                EstCount++;
                    
            }



        });

    });


</script>

























